﻿using System;
using System.Collections.Generic;

namespace Lotto.Core
{
    public class LotteryNumberCalculator
    {
        /// <summary>
        /// Calculate a set of lottery numbers
        /// </summary>
        /// <param name="count">Number of lottery numbers to calculate, e.g. 6</param>
        /// <param name="range">Maximum allowed value, e.g. 49</param>
        /// <returns>Array of lottery numbers</returns>
        public static int[] Calculate(int count, int range)
        {
            Random random = new Random();

            List<int> resultList = new List<int>();

            for (int i = 0; i < count; i++)
            {
                int number;

                do
                {
                    // find number that is not already part of result list
                    number = random.Next(1, range + 1);
                }
                while (resultList.Contains(number));

                resultList.Add(number);
            }

            resultList.Sort();

            return resultList.ToArray();
        }
    }
}
